<?php
/**
 * If you are not authorized to modify this file, do NOT touch it.
 * @file timer.func.php
 * @author SkyWorld
 * @date 2011-1-18
 * @description This file contains all funtions about time calculating
 **/

if(!defined('IN_NCG')) exit ('Access Denied.');

    /**
	 * @name Timer
	 * @author SkyWorld
	 * @date 2011-1-18
	 * @description this function to call will set up a node to calculate time
     * @parameters  void
     * @return void
     **/
function Timer()
{
	global $timerResults;
	$curTime = microtime(true);

	$trace = debug_backtrace();

	$timerResults[] = array(
		'line' => $trace[0]['line'],
		'file' => $trace[0]['file'],
		'func' => isset($trace[1]['function']) ? $trace[1]['function'] : '',
		'time' => $curTime
	);
}


    /**
	 * @name TimerNext
	 * @author SkyWorld
	 * @date 2011-1-18
	 * @description this function to call will calculate time between two node
     * @parameters  void
     * @return void
     **/
//Timer();
function TimerNext()
{
	global $timerResults;
	$result = 'Timing Results';
	$clock  = @$timerResults[0]['time'];

	foreach ($timerResults as $tr)
	{
		$thisTime = $tr['time'] - $clock;
		$clock = $tr['time'];
		$fn = basename($tr['file']);
		$pretty = number_format($thisTime,5);

		$result = $pretty;
//		$result .= "\n{$pretty} secs - File: {$fn} -Line: {$tr['line']}";
//		if($tr['func'])
//		{
//			$result .= "-Calling Function: {$tr['func']}";
//		}
	}

	return $result;
}
?>
